package io.jft.doll.tcp

import io.jft.doll.tcp.event.TcpData
import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.EmptyByteBuf

/**
 * Created by G on 2017/12/25 0025.
 */
class TcpC {
    companion object {
        const val HEAD_LENGTH: Int = 12
        const val PROTOCOL_HEADER: Long = 0xaa55aa55

        const val RECONNECT_TIME: Long = 30000L

        const val TCP_SERVER = "wwj.jzz18.cn"
        const val TCP_SERVER_PORT = 9911

        const val COMD_LOGIN = 0x0001.toShort() //登录
        const val COMD_REP_LOGIN = 0x0002.toShort() //登录响应
        const val COMD_APPOINTMENT = 0x0003.toShort() //发起预约
        const val COMD_REP_APPOINTMENT = 0x0004.toShort() //预约响应
        const val COMD_REP_TURN_YOUT = 0x0005.toShort() //轮到通知
        const val COMD_TURN_YOUT = 0x0006.toShort() //响应轮到
        const val COMD_TOKEN = 0x0007.toShort() //返回Token
        const val COMD_REP_EXCEPTION = 0x0008.toShort() //返回异常
        const val COMD_OPERATE = 0x0009.toShort() //操作娃娃机
        const val COMD_REP_AMOUNT = 0x000A.toShort() //返回数量
        const val COMD_HEART = 0x000B.toShort() //心跳
        const val COMD_REP_HEART = 0x000C.toShort() //心跳响应
        const val COMD_REP_ROOMSTATUS_CHANGE = 0x000D.toShort() //房间状态变化
        const val COMD_REP_QUENED_CHANGE = 0x000E.toShort() //排队人数变化
        const val COMD_REP_MY_QUNEND_CHANGE = 0x000F.toShort() //排队名次变化
        const val COMD_ABORD_APPOINTMENT_CHANGE = 0x0010.toShort() //取消预约
        const val COMD_REP_ABORD_APPOINTMENT_CHANGE = 0x0011.toShort() //取消预约响应

        val HEART_BEAT by lazy { TcpData(COMD_HEART, EmptyByteBuf(ByteBufAllocator.DEFAULT)) }


        fun comToString(cmd: Short) = when (cmd) {
            COMD_LOGIN -> "登录"
            COMD_REP_LOGIN -> "登录响应"
            COMD_APPOINTMENT -> "发起预约"
            COMD_REP_APPOINTMENT -> "预约响应"
            COMD_REP_TURN_YOUT -> "轮到通知"
            COMD_TURN_YOUT -> "响应轮到"
            COMD_TOKEN -> "返回Token"
            COMD_REP_EXCEPTION -> "返回异常"
            COMD_OPERATE -> "操作娃娃机"
            COMD_REP_AMOUNT -> "返回数量"
            COMD_HEART -> "心跳"
            COMD_REP_HEART -> "心跳响应"
            COMD_REP_ROOMSTATUS_CHANGE -> "房间状态变化"
            COMD_REP_QUENED_CHANGE -> "排队人数变化"
            COMD_REP_MY_QUNEND_CHANGE -> "排队名次变化"
            COMD_ABORD_APPOINTMENT_CHANGE -> "取消预约"
            COMD_REP_ABORD_APPOINTMENT_CHANGE -> "取消预约响应"
            else -> "未知"
        }
    }
}